package source.events.action;

import source.model.*;
import source.model.type.ActionResult;
import source.model.type.GameObjectType;
import source.view.MainScreen;
import source.model.skill.*;

/**
 * Sneak class is responsible for sneaking the current unit.  If the
 * current selection is not a unit, the Action fails.
 * @author Joe/Tristan
 *
 */
public class Sneak implements Action{

	private Unit unit;
	
	public Sneak()
	{
		
	}
	public ActionResult execute( DataHandler dh ) {
		GameObject go = dh.getCurrentSelection();

		if(go.objectType() != GameObjectType.UNIT)
		{
			MainScreen.writeToConsole("Current selection is not an unit");
			return ActionResult.FAILED;
		}
		
		
		this.unit = (Unit)go;
		if(unit.getMissionFlag())
		{
			MainScreen.writeToConsole("Current selection is on a mission");
			return ActionResult.IMPOSSIBLE;
		}
		SkillSneak sneaker = (SkillSneak)unit.getSkill("sneak");
		if (sneaker == null){
			MainScreen.writeToConsole(unit.getName() + " cannot sneak!!");
			return ActionResult.IMPOSSIBLE;
		}
		
		/*
		if (sneaker.isSneaking()){
			MainScreen.writeToConsole(unit.getName() + " is already sneaking!!");
			return ActionResult.SUCCESS;
		}*/
		
		sneaker.sneak();
		MainScreen.writeToConsole(unit.getName() + " is " + 
				(sneaker.isSneaking() ? "now sneaking." : "no longer sneaking."));
		
		return ActionResult.SUCCESS;
	}
}
